﻿package mortal.game.view.group.cellRenderer
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.menu.*;
    import mortal.mvc.core.*;

    public class TeamMateCellRenderer extends GCellRenderer
    {
        private var _teamMateInfo:SGroupPlayer;
        private var _selectedBg:ScaleBitmap;
        private var _bg:GBitmap;
        private var _level:GTextFiled;
        private var _playerName:GTextFiled;
        private var _operOutBtn:GButton;
        private var _vipIcon:GImageBitmap;
        private var _captainIcon:GBitmap;
        private var _farIcon:GBitmap;
        private var _career:GTextFiled;
        private var _fightPower:GTextFiled;
        private var _captainText:GTextFiled;
        private var _buffTips:GTextFiled;

        public function TeamMateCellRenderer()
        {
            return;
        }// end function

        override protected function initSkin() : void
        {
            var _loc_1:* = new GBitmap();
            var _loc_2:* = ResourceConst.getScaleBitmap(ImagesConst.selectedBg);
            this.setStyle("downSkin", _loc_2);
            this.setStyle("overSkin", _loc_2);
            this.setStyle("upSkin", _loc_1);
            this.setStyle("selectedDownSkin", _loc_2);
            this.setStyle("selectedOverSkin", _loc_2);
            this.setStyle("selectedUpSkin", _loc_2);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gBitmap("", 2, 2, this);
            var _loc_1:* = GlobalStyle.textFormatBai;
            this._level = UIFactory.gTextField("", 15, 5, 50, 20, this, _loc_1);
            this._career = UIFactory.gTextField("", 20, 263, 50, 20, this, _loc_1);
            _loc_1.underline = true;
            this._playerName = UIFactory.gTextField("", 60, 5, 80, 20, this, _loc_1);
            _loc_1 = GlobalStyle.textFormatAnjin;
            this._fightPower = UIFactory.gTextField("", 45, 264, 100, 20, this, GlobalStyle.textFormatChen);
            this._captainText = UIFactory.gTextField(Language.getString(30209), 70, 235, 60, 20, this, _loc_1);
            this._vipIcon = UIFactory.gImageBitmap("", 3, 21, this);
            this._farIcon = UIFactory.gBitmap("", 58, 114, this);
            this._captainIcon = UIFactory.gBitmap(ImagesConst.Captain, 40, 232, this);
            this._operOutBtn = UIFactory.gButton("", 36, 236, 78, 22, this);
            this._operOutBtn.configEventListener(MouseEvent.CLICK, this.operHandler);
            _loc_1 = GlobalStyle.textFormatHuang2.center();
            _loc_1.size = 14;
            this._buffTips = UIFactory.gTextField("", 25, 110, 100, 50, this, _loc_1);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            PlayerMenuRegister.UnRegister(this._playerName);
            this._bg.dispose(param1);
            this._level.dispose(param1);
            this._playerName.dispose(param1);
            this._operOutBtn.dispose(param1);
            this._vipIcon.dispose(param1);
            this._captainIcon.dispose(param1);
            this._career.dispose(param1);
            this._fightPower.dispose(param1);
            this._captainText.dispose(param1);
            this._farIcon.dispose(param1);
            this._bg = null;
            this._level = null;
            this._playerName = null;
            this._operOutBtn = null;
            this._vipIcon = null;
            this._captainIcon = null;
            this._career = null;
            this._captainText = null;
            this._fightPower = null;
            this._farIcon = null;
            this._buffTips.dispose(param1);
            this._buffTips = null;
            this._teamMateInfo = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function operHandler(event:MouseEvent) : void
        {
            if (Cache.instance.group.isInGroup)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GroupKickOut, this._teamMateInfo.player.entityId));
            }
            else
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GroupCreateGroup));
            }
            return;
        }// end function

        private function setCareer(param1:int) : void
        {
            this._career.visible = true;
            this._career.text = GameDefConfig.instance.getECarrerShot(param1);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:BitmapData = null;
            var _loc_3:EntityInfo = null;
            var _loc_4:BitmapData = null;
            this._teamMateInfo = param1.data;
            this._operOutBtn.visible = false;
            this._farIcon.visible = false;
            PlayerMenuRegister.UnRegister(this._playerName);
            if (this._teamMateInfo)
            {
                this._buffTips.text = "";
                this.setCareer(this._teamMateInfo.player.career);
                this.mouseEnabled = true;
                this.mouseChildren = true;
                this._fightPower.text = Language.getString(30256) + this._teamMateInfo.player.combat;
                _loc_2 = new BitmapData(150, 287, true, 16777215);
                this._bg.bitmapData = _loc_2;
                if (this._teamMateInfo.player.VIP)
                {
                    this._vipIcon.visible = true;
                    this._vipIcon.imgUrl = GameDefConfig.instance.getVipLevelIconUrl(this._teamMateInfo.player.VIP);
                }
                else
                {
                    this._vipIcon.visible = false;
                }
                this._vipIcon.visible = this._teamMateInfo.player.VIP > 0;
                this._level.text = "Lv. " + this._teamMateInfo.player.level;
                if (!Cache.instance.group.isInGroup)
                {
                    this._operOutBtn.visible = true;
                    this._operOutBtn.label = Language.getString(30237);
                    var _loc_5:Boolean = false;
                    this._captainIcon.visible = false;
                    this._captainText.visible = _loc_5;
                    this._vipIcon.visible = Cache.instance.vip.level > 0;
                    PlayerMenuRegister.Register(this._playerName, this._teamMateInfo.player, PlayerMenuConst.GroupSelfOpMenu);
                    this._playerName.htmlText = "<a href=\'event:#\'>" + this._teamMateInfo.player.name + "</a>";
                }
                else if (Cache.instance.group.isCaptain)
                {
                    _loc_3 = Cache.instance.entity.getEntityInfoById(this._teamMateInfo.player.entityId);
                    if (_loc_3)
                    {
                        this._playerName.htmlText = "<a href=\'event:#\'>" + _loc_3.entityInfo.name + "</a>";
                    }
                    else
                    {
                        this._playerName.htmlText = "<a href=\'event:#\'>" + this._teamMateInfo.player.name + "</a>";
                    }
                    if (!Cache.instance.group.isCaptainById(this._teamMateInfo.player.entityId))
                    {
                        this._operOutBtn.visible = true;
                        this._operOutBtn.label = Language.getString(30238);
                        var _loc_5:Boolean = false;
                        this._captainIcon.visible = false;
                        this._captainText.visible = _loc_5;
                        PlayerMenuRegister.Register(this._playerName, this._teamMateInfo.player, PlayerMenuConst.GroupMemberOpMenu);
                    }
                    else
                    {
                        this._operOutBtn.visible = false;
                        var _loc_5:Boolean = true;
                        this._captainIcon.visible = true;
                        this._captainText.visible = _loc_5;
                        PlayerMenuRegister.Register(this._playerName, this._teamMateInfo.player, PlayerMenuConst.GroupSelfOpMenu);
                    }
                    if (Cache.instance.entity.getEntityInfoById(this._teamMateInfo.player.entityId) == null)
                    {
                        if (this._teamMateInfo.player.online == 0)
                        {
                            this._farIcon.bitmapData = GlobalClass.getBitmapData(ImagesConst.Offline);
                        }
                        else
                        {
                            this._farIcon.bitmapData = GlobalClass.getBitmapData(ImagesConst.leave);
                        }
                        this._farIcon.visible = true;
                    }
                }
                else
                {
                    this._operOutBtn.visible = false;
                    this._playerName.htmlText = "<a href=\'event:#\'>" + this._teamMateInfo.player.name + "</a>";
                    if (!Cache.instance.group.isCaptainById(this._teamMateInfo.player.entityId))
                    {
                        var _loc_5:Boolean = false;
                        this._captainIcon.visible = false;
                        this._captainText.visible = _loc_5;
                    }
                    else
                    {
                        var _loc_5:Boolean = true;
                        this._captainIcon.visible = true;
                        this._captainText.visible = _loc_5;
                    }
                    if (EntityUtil.isSelf(this._teamMateInfo.player.entityId))
                    {
                        PlayerMenuRegister.Register(this._playerName, this._teamMateInfo.player, PlayerMenuConst.GroupSelfOpMenu);
                    }
                    else
                    {
                        PlayerMenuRegister.Register(this._playerName, this._teamMateInfo.player, PlayerMenuConst.GroupMemberOpMenu);
                    }
                    if (Cache.instance.entity.getEntityInfoById(this._teamMateInfo.player.entityId) == null)
                    {
                        if (this._teamMateInfo.player.online == 0)
                        {
                            this._farIcon.bitmapData = GlobalClass.getBitmapData(ImagesConst.Offline);
                        }
                        else
                        {
                            this._farIcon.bitmapData = GlobalClass.getBitmapData(ImagesConst.leave);
                        }
                        this._farIcon.visible = true;
                    }
                }
            }
            else
            {
                this.mouseEnabled = false;
                this.mouseChildren = false;
                _loc_4 = new BitmapData(150, 287, true, 16777215);
                this._bg.bitmapData = _loc_4;
                this._vipIcon.visible = false;
                this._captainIcon.visible = false;
                this._captainText.visible = false;
                this._operOutBtn.visible = false;
                this._career.visible = false;
                this._level.text = "";
                this._playerName.text = "";
                this._fightPower.text = "";
                this._buffTips.text = (param1.index + 1) + Language.getString(35304) + (param1.index + 1) * 5 + "%";
            }
            return;
        }// end function

    }
}
